from core.api_util import api_util
from utils.response_util import process_response

"""
接口方法
"""


def send_code(json_data):
    """
    获取短信验证码
    :param json_data:  json格式---> (optional) json to send in the body of the :class:`Request`.
    :return:
    """
    response = api_util.get_code(json=json_data)
    return process_response(response)


def register(code, mobile):
    """
    注册接口
    :param code:
    :param mobile:
    :return:
    """
    json_data = {
        "code": str(code),
        "password": "123456",
        "username": str(mobile)
    }
    response = api_util.register_mobile(json=json_data)
    return process_response(response)


def login(username, password):
    """
    登录
    :param username:
    :param password:
    :return:
    """
    json_data = {
        "username": username,
        "password": password
    }
    response = api_util.user_login(json=json_data)
    return process_response(response)


def add_shopping_cart(json_data, headers):
    """
    加购物车---优化版
    header请求头：token
    :param headers:
    :param json_data:goods&nums  token:用户信息
    :return:请求响应
    """
    response = api_util.user_add_goods(json=json_data, headers=headers)
    return process_response(response)


def add_message(data, files, headers):
    """
    留言上传-----优化版
    :param files:
    :param headers:
    :param data:data格式--->(optional) Dictionary, list of tuples, bytes, or file-like
    :return:
    """
    response = api_util.user_add_message(data=data, files=files, headers=headers)
    return process_response(response)


"""
优化前加购 & 留言上传版
"""
# def add_shopping_cart(json_data,token):
#     """
#     加购物车
#     header请求头：token
#     :param params:goods&nums  token:用户信息
#     :return:请求响应
#     """
#
#     #优化掉组装部分
#     #实际header：Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxNjg4OTIsInVzZXJuYW1lIjoiMTU4MTk3NDk1NTIiLCJleHAiOjE3MjY0ODg5MTUsImVtYWlsIjpudWxsfQ.X7Nzzy0W-xm6016uDAHIbxQmz56bm0NbFSd74GMIKT8
#     headers = {
#         'Authorization': 'JWT '+ token
#     }
#     response = api_util.user_add_goods(json = json_data, headers=headers)
#     return process_response(response)
#
# def add_message(data, files, token):
#     """
#     留言上传
#     :param data:data格式--->(optional) Dictionary, list of tuples, bytes, or file-like
#     :param token:
#     :return:
#     """
#     headers = {
#         'Authorization': 'JWT ' + token
#     }
#
#     response = api_util.user_add_message(data=data, files = files, headers=headers)
#     return process_response(response)
